package http

import (
	"bytes"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
	"io"
)

// ReqID 请求参数
type ReqID struct {
	ID int64 `json:"id,string" binding:"required" msg:"请输入id"`
}

// GetRequestParam 解析请求参数
func GetRequestParam(c *gin.Context) []byte {
	data, err := c.GetRawData()
	if err != nil {
		panic(err)
	}
	// 将参数传递重新传递给接口
	c.Request.Body = io.NopCloser(bytes.NewBuffer(data))
	return data
}

// GetPaginationParam 获取分页数据
func GetPaginationParam(c *gin.Context) (currPage, pageSize int) {
	currPage = cast.ToInt(c.Query("currPage"))
	pageSize = cast.ToInt(c.Query("pageSize"))
	return currPage, pageSize
}
